var model = require('./connect.js')
var sendAuthCode = require('../modules/sendAuthCode.js')
var UserModel = model.UserModel
var ArticleModel = model.ArticleModel
var BetterArticleModel = model.BetterArticleModel

//默认路径
var GETPATH = './routes/get/'
var POSTPATH = './routes/post/'

/*GET 请求加载区域*/
var index = require(GETPATH + 'index.js')
var article = require(GETPATH + 'article.js')(ArticleModel)   //--  集合
var authCode = require(GETPATH + 'authCode.js')(sendAuthCode)
var user = require(GETPATH + 'user.js')(UserModel, ArticleModel)
var homeData = require(GETPATH + 'homeData.js')(UserModel, ArticleModel)
var applyBetter_get = require(GETPATH + 'applyBetter.js')(ArticleModel, BetterArticleModel)

/*POST 请求加载区域*/
var login = require(POSTPATH + 'login.js')(UserModel)
var login2 = require(POSTPATH + 'login2.js')(UserModel)
var register = require(POSTPATH + 'register.js')(UserModel)
var register2 = require(POSTPATH + 'register2.js')(UserModel)
var publishArticle = require(POSTPATH + 'publishArticle.js')(ArticleModel, UserModel)
var updateArticle = require(POSTPATH + 'updateArticle.js')(ArticleModel, UserModel)  // -- 集合
var authCodeTest = require(POSTPATH + 'authCodeTest.js')  // 验证码
var updateUser = require(POSTPATH + 'updateUser.js')(UserModel)
var applyBetter_post = require(POSTPATH + 'applyBetterCheck.js')(BetterArticleModel, ArticleModel, UserModel)
var applyBetter = require(POSTPATH + 'applyBetter.js')(BetterArticleModel)

/*admin验证*/
var admin = require(POSTPATH + 'admin.js')


module.exports = function (app) {
  
  app.get('/', index)

  /*文章表部分*/
  //  获取第一次进入首页时的数据
  app.get('/homeData', homeData)
  //  获取当前id文章
  app.get('/article/id', article.id)
  //  获取作者全部文章
  app.get('/article/autor', article.autor)
  //  分页获取文章
  app.get('/article/page', article.page)
  //  获取全部精品文章
  app.get('/article/better', article.better)
  //  获取最好文章5篇
  app.get('/article/good', article.good)
  //  获取最新文章5篇
  app.get('/article/time', article.time)
  //  获取文章数目
  app.get('/article/number', article.number)

  app.post('/applyBetter', applyBetter)


  //  获取邮箱验证码
  app.get('/authCode', authCode )
  //  用户登陆
  app.post('/login', login2)
  //  注册用户
  app.post('/register', register2)
  //  发表文章
  app.post('/publishArticle', publishArticle)
  //  文章评论
  app.post('/updateArticle/comment', updateArticle.comment)
  /*//  文章加精  -- 管理员权限
  app.post('/updateArticle/better', updateArticle.better)*/
  //  文章的其他动态
  var keys = ['read', 'good', 'bad', 'collected']
  keys.map(function (key) {
    app.post('/updateArticle/' + key, updateArticle[key])
  })

  /*用户表部分*/
  // 获取用户信息
  app.get('/user', user)
  // 核对验证码
  app.post('/authCodeTest', authCodeTest)
  
  // 更改用户信息
  Object.keys(updateUser).map(function (item) {
    app.post('/updateUser/' + item, updateUser[item])
  })

  /*管理员部分*/
  // 验证管理员
  app.post('/admin', admin)
  // 获取精品文章申请
  app.get('/applyBetterCheck', applyBetter_get)
  // 批改申请
  app.post('/applyBetterCheck', applyBetter_post)

}